package com.organize.rules.impl;

import com.autumn.util.StringUtils;
import com.organize.rules.ComponentRule;
import com.organize.rules.ComponentRuleContext;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;

/**
 * <p>
 * </p>
 *
 * @description TODO
 * @author: 老码农
 * @create: 2020-10-15 18:30
 **/
public class ComponentRuleContextImpl implements ComponentRuleContext {

    private Map<String, ComponentRule> ruleMap = new HashMap<String, ComponentRule>(16);

    public void registerRule(ComponentRule rule) {
        this.ruleMap.put(rule.getName().toLowerCase(), rule);
    }

    public ComponentRule getRule(String name) {
        if (StringUtils.isNullOrBlank(name)) {
            return null;
        }
        return this.ruleMap.get(name.trim().toLowerCase());
    }

    public Collection<ComponentRule> getRules() {
        return this.ruleMap.values();
    }
}
